package com.txunda.zhuohired.aty.user.my;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.ants.theantsgo.util.JSONUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.lidroid.xutils.view.annotation.event.OnClick;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.base.BaseAty;
import com.txunda.zhuohired.http.pst.InfoPst;

import java.util.Map;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/9 17:05
 * 功能描述：意见反馈
 * 联系方式：jiahuanchen@126.com
 */

public class OpinionAty extends BaseAty {
    /**
     * 标题
     */
    @ViewInject(R.id.tv_layout_white_center)
    private TextView tv_layout_white_center;
    /**
     * 提交
     */
    @ViewInject(R.id.tv_layout_white_right)
    private TextView tv_layout_white_right;
    @ViewInject(R.id.tv_opinion_content)
    private EditText tv_opinion_content;
    @ViewInject(R.id.ev_opinion_phont)
    private  EditText ev_opinion_phont;

    private String feedback_text;
    private String from_phone;
    private InfoPst infoPst;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        showStatusBar(R.id.layout_white_head);
        tv_layout_white_center.setText("意见反馈");
        tv_layout_white_right.setVisibility(View.VISIBLE);
        tv_layout_white_right.setText("提交");
    }
    @OnClick({R.id.tv_layout_white_right})
    @Override
    public void onClick(View v) {
        super.onClick(v);
        switch (v.getId()){
            case R.id.tv_layout_white_right:
                closeKeyboard(this,tv_opinion_content);
                closeKeyboard(this,ev_opinion_phont);
                feedback_text = tv_opinion_content.getText().toString().trim();
                from_phone = ev_opinion_phont.getText().toString().trim();
                infoPst.feedback(feedback_text,from_phone);
                break;
        }
    }

    @Override
    protected int getLayoutResId() {
        return R.layout.aty_opinion;
    }

    @Override
    protected void initialized() {
        infoPst = new InfoPst(this);
    }

    @Override
    protected void requestData() {

    }

    @Override
    public void onComplete(String requestUrl, String jsonStr) {
        super.onComplete(requestUrl, jsonStr);
        if(requestUrl.contains("feedback")){
            Map<String,String> map = JSONUtils.parseKeyAndValueToMap(jsonStr);
            if(map.get("code").equals("1")){
                showToast(map.get("message"));
                finish();
            }
        }
    }
}
